//
//  YSFlowJobDelineateViewController.m
//  YaSha-iOS
//
//  Created by YaSha_Tom on 2018/10/22.
//  Copyright © 2018年 亚厦装饰股份有限公司. All rights reserved.
//

#import "YSFlowJobDelineateViewController.h"
#import "YSFlowFormListCell.h"

@interface YSFlowJobDelineateViewController ()
@property (nonatomic,strong) NSMutableArray *handleArray;
@end

@implementation YSFlowJobDelineateViewController
- (NSMutableArray *)handleArray {
    if (!_handleArray) {
        _handleArray = [NSMutableArray array];
    }
    return _handleArray;
}
- (void)initTableView {
    [super initTableView];
    [self setUpData:self.dic];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"岗位描述";
}
#pragma mark -- 数据封装
- (void)setUpData:(NSDictionary *)dic {
    
    [self.handleArray addObject:@{@"title":@"岗位名称",@"content":self.dic[@"positionName"],@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"所属中心/部门",@"content":self.dic[@"departmentName"],@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"岗位职级",@"content":[NSString stringWithFormat:@"%@",self.dic[@"num"]] ,@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"岗位编号",@"content":[NSString stringWithFormat:@"%@",self.dic[@"positionId"]],@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"直接上级",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"直接下级",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"岗位职责",@"content":@" ",@"special":@"3"}];
    [self.handleArray addObject:@{@"title":@"任职资格",@"content":@" ",@"special":@"1"}];
    [self.handleArray addObject:@{@"title":@"学历",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"专业",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"工作经验",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"知识",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"能力",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"其他",@"content":@" ",@"special":@"0"}];
    [self.handleArray addObject:@{@"title":@"备注",@"content":@" ",@"special":@"1"}];
    [self.handleArray addObject:@{@"title":@"备注",@"content":@" ",@"special":@"0"}];
    self.dataSourceArray = self.handleArray;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)indexPath.section,(long)indexPath.row];//以indexPath来唯一确定cell
        YSFlowFormListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
        if (cell == nil) {
            cell = [[YSFlowFormListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        [cell setNewFlowDetailWithDictionary:self.dataSourceArray[indexPath.row]];
        return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
    if (indexPath.section == 0) {
        NSDictionary *dic = self.dataSourceArray[indexPath.row];
        if ([dic[@"special"] isEqualToString:@"3"]) {
            YSFlowFormListCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
            if (cell.button.selected) {
                cell.button.selected = NO;
                [self.dataSourceArray removeObjectAtIndex:indexPath.row+1];
                [self.tableView beginUpdates];
                NSIndexPath *indexPathDelete = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
                [self.tableView deleteRowsAtIndexPaths:@[indexPathDelete] withRowAnimation:UITableViewRowAnimationAutomatic];
                [self.tableView endUpdates];
                
            }else{
                cell.button.selected = YES;
                [self.dataSourceArray insertObject:@{@"title":@"",@"content":@"111",@"special":@"4"} atIndex:indexPath.row+1];
                [self.tableView beginUpdates];
                NSIndexPath *indexPathAdd = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
                [self.tableView insertRowsAtIndexPaths:@[indexPathAdd] withRowAnimation:UITableViewRowAnimationAutomatic];
                [self.tableView endUpdates];
            }
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
